<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // Promise ajax
        const ajax = (url)=>{
            return new Promise((resolve,reject)=>{
                var xhr = new XMLHttpRequest()
                xhr.open('get', url)
                xhr.responseType = "json"
                xhr.onload = function () {
                    if(this.status === 200){
                        resolve(this.response)
                    }else{
                        reject(new Error(this.statusText))
                    }
                }
                // 初始化XMLHttpRequest对象时，是没有sent方法
                xhr.send()
            })
        }

        ajax('/part-1/javascript-asyn/code/test.json').then(
            response=> console.log(response),
            error=> console.log(error)
        )
    </script>
</body>
</html>